import { Key } from 'react'
import request from '../utils/request'
export interface StudentType {
  objectId?:string
  name:string,
  code:string,
  stuClass:Array<string>,
  gender:string
  avatar:string
}
//新增学员
export const studentPost = (studentData:StudentType)=>{
  return request.post('/classes/student',studentData)
}

//学员列表
interface ConditionType {
  gender:string
}
export const studentGet = (condition?:ConditionType)=>{
  let where = condition ? JSON.stringify(condition) : '{}'
  return request.get(`/classes/student?where=${where}`)
}

//编辑学员
export const studentPut = (objectId:string,studentData:StudentType)=>{
  return request.put(`/classes/student/${objectId}`,studentData)
}

//删除学员
export const studentDel = (objectId:string)=>{
  return request.delete(`/classes/student/${objectId}`)
}

//批量操作
export const studentBatch = (deleteIds:Array<Key>)=>{
  let requests = deleteIds.map(id=>{
    return {
      "method": "DELETE",
      "path": `/1.1/classes/student/${id}`,
    }
  })
  return request.post('/batch',{requests})
}